/**
 * @param {number} n
 * @param {number} k
 * @return {number}
 */
 var kthGrammar = function(n, k) {
   if(k==1) return 0
   if(k==2) return 1
  //  let dp = ['','']
   let pre = '0110'
   let res = pre
   for(let i=4;i<=n;i++){
    res = pre+'1001'+pre.slice(0,pre.length-4)
    pre = res
   }
   console.log(dp);
   return res[k-1]
   
};
console.log(1<<3);
// console.log(kthGrammar(7,3));